#!/usr/bin/python
#coding: utf-8

import urllib2


class PageDownloader():
    def __init__(self, url):
        self.url = url
        self.doc = None
        for i in range(3):      # 如果下载失败，将进行三次尝试
            self.doc = self.download_page()
            if not self.doc is None:
                break

    def download_page(self):
        u = urllib2.urlopen(self.url)
        if u is None:
            return None
        doc = u.read()
        self.doc = doc
        return doc

    def get_document(self):
        if self.doc is None:
            self.doc = self.download_page()
        return self.doc





